package com.zfk.transaction.controller;


import com.alibaba.fastjson.JSON;
import com.zfk.transaction.entity.User;
import com.zfk.transaction.entity.home.ResultBean;
import com.zfk.transaction.mapper.UserMapper;
import com.zfk.transaction.service.HomeService;
import com.zfk.transaction.service.UserService;
import com.zfk.transaction.util.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/home")
@Api("HomeController")
public class HomeController {

    @Autowired
    private HomeService homeService;

    @Autowired
    private UserService userService;

    @GetMapping
    @ApiOperation("获得首页数据")
    public Response getHomeData(){
        ResultBean data = homeService.getHomeData();
        return Response.ok(data);
    }

    @PostMapping("/updateUser")
    @ApiOperation("修改用户信息")
    public Response updateUser(@RequestBody Map<String,Object> jsonString){
        Object userJson = jsonString.get("user");


        String string = JSON.toJSONString(userJson);

        Map<String,Object> map = JSON.parseObject(string, Map.class);
        System.out.println(map.get("id"));
        User user = new User((Integer)map.get("id"),(String) map.get("email"),(String)map.get("userName"),(String)map.get("password"),(String)map.get("phone"));
        System.out.println(user);
        int i = userService.updateUser(user);

        return Response.ok();
    }

}
